package com;

import java.sql.Connection;
import java.sql.Statement;

public class JDBC_03_NoTransaction {

	public static void main(String[] args) {
		Connection connection = null;
		Statement statement = null;
		try {
			connection = DBUtil.getConnection();

			// 取消自动提交
			connection.setAutoCommit(false);

			statement = connection.createStatement();

			statement.addBatch("insert into test (name,age) values ('张三_1',18)");
			statement.addBatch("insert into test (name,age) values ('张三_2',18)");
			statement.addBatch("insert into test (name,age) values ('张三_3',18)");

			statement.executeBatch();

			// 提交
			connection.commit();
		} catch (Exception e) {
			e.printStackTrace();

			// 事物回滚

			try {
				connection.rollback();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		} finally {
			try {

				// 开启自动提交
				connection.setAutoCommit(true);
				DBUtil.close(statement);
				DBUtil.close(connection);
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		System.out.println("111111");
	}

}
